﻿using Best.SmartCms.Domain;
using Best.SmartCms.Dto.Response;
using Best.SmartCms.Dto;
using Best.SmartCms.Service;
using Microsoft.AspNetCore.Mvc;

namespace Best.SmartCms.API.Controllers
{
    /// <summary>
    /// News
    /// </summary>
    public class NewsController : Controller
    {
        private readonly NewsService _newsService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="newsService"></param>
        public NewsController(NewsService newsService)
        {
            _newsService = newsService;
        }


        /// <summary>
        /// 列表分页.
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("news/pagelist")]
        public PagedResponse<NewsListDto> PageList([FromBody]NewsListQueryDto query)
        {
            var ret = _newsService.PageList(query);
            return ret;
        }


        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("news/create")]
        public ApiResponse Create([FromBody]NewsEditDto dto)
        {
             _newsService.Create(dto);
            return ApiResponse.Succeeds();
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("news/edit")]
        public ApiResponse Edit([FromBody]NewsEditDto dto)
        {
            _newsService.Edit(dto);
            return ApiResponse.Succeeds();
        }


        /// <summary>
        /// 详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("news/Info")]
        public ApiResponse<NewsEditDto> Info(long id)
        {
            var ret = _newsService.Info(id);
            return ApiResponse<NewsEditDto>.Succeeds(ret);
        }


        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("news/delete")]
        public ApiResponse Delete(long id)
        {
            _newsService.Delete(id);
            return ApiResponse.Succeeds();
        }
    }
}